﻿using Microsoft.Win32;
using SolidworksDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestExe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            SolidWorksHelp.Test();
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (b)
            {
                MessageBox.Show("获取成功");

            }
            else
            {
                MessageBox.Show("获取失败");
            }

        }

        private void Button3_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetFristSolidWorksRunningObject();
            if (b)
            {
                MessageBox.Show("获取成功");

            }
            else
            {
                MessageBox.Show("获取失败");
            }
        }

        private void Button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(SolidWorksHelp.GetSwAppPath());
            

        }

        private void Button5_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.OpenSwApp();
            if (b)
            {
                MessageBox.Show("获取成功");

            }
            else
            {
                MessageBox.Show("获取失败");
            }
        }

        private void Button6_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false==b)
            { 
                MessageBox.Show("获取失败");
                return;
            }

            MessageBox.Show("路径：" + TestSW.GetPath() + ",版本：" + TestSW.GetVer());

            TestSW.MakeWindowsSate(1);
            Thread.Sleep(2*1000);
            TestSW.MakeWindowsSate(2);
        }

        private void Button7_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string temPath = @"C:\ProgramData\SolidWorks\SOLIDWORKS 2022\templates\gb_part.prtdot";
            string result = ModelDocHelp.NewDocumnet(temPath);
            if (result == "")
            {
                MessageBox.Show("创建零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }

        }

        private void Button8_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string partPath = @"C:\Users\xzzfx\Desktop\新建文件夹\测试模型-零件001.sldprt";
            string result = ModelDocHelp.SaveDoc(partPath);
            if (result == "")
            {
                MessageBox.Show("保存零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }
        }

        private void Button9_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string partPath = @"C:\Users\xzzfx\Desktop\新建文件夹\测试模型-零件002.sldprt";
            string result = ModelDocHelp.OpenDoc(partPath);
            if (result == "")
            {
                MessageBox.Show("打开零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }
        }

        private void Button10_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            List<string> paths=ModelDocHelp.GetAllDoc();
            foreach (var item in paths)
            {
                textBox1.AppendText(Environment.NewLine + item);
            }
        }

        private void Button11_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string str = ModelDocHelp.GetActiveDoc();
            textBox1.AppendText(Environment.NewLine + str);
        }

        private void Button12_Click(object sender, EventArgs e)
        {

            bool b = SolidWorksHelp.GetSwAPP();
            if (false == b)
            {
                MessageBox.Show("获取SolidWorks失败");
                return;
            }
            string str = ModelDocHelp.GetEditTarget();
            textBox1.AppendText(Environment.NewLine + str);
        }
    }
}
